using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnermyGenerater : MonoBehaviour
{
    public List<GameObject> objs = new List<GameObject>();

    private float delayDistance;
    [SerializeField]
    private float MinDelayDistance, MaxDelayDistance;
    [SerializeField]
    private int StartDistance;

    [SerializeField]
    private List<float> weight = new List<float>();

    private void Start()
    {
        delayDistance = StartDistance;
    }

    private void Update()
    {
        if (delayDistance < GameManager.instance.Distance)
        {
            delayDistance += Random.Range(MinDelayDistance, MaxDelayDistance);

            float random = Random.Range(0f, 1f);
            for (int i = 0; i < weight.Count - 1; i++)
            {
                if (weight[i + 1] > random && weight[i] < random)
                {
                    GameObjectsPool.instance.Instantiate(objs[i], transform.position);
                    break;
                }
            }
        }
    }
}
